﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// BloomEffect Effect
    /// </summary>
    public class BloomEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BloomEffect), 0);
        public static readonly DependencyProperty BloomIntensityProperty = DependencyProperty.Register("BloomIntensity", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty BaseIntensityProperty = DependencyProperty.Register("BaseIntensity", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty BloomSaturationProperty = DependencyProperty.Register("BloomSaturation", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(2)));
        public static readonly DependencyProperty BaseSaturationProperty = DependencyProperty.Register("BaseSaturation", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(3)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(BloomEffect.InputProperty));
            }
            set
            {
                this.SetValue(BloomEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne le BaseIntensity
        /// </summary>
        public double BaseIntensity
        {
            get
            {
                return ((double)this.GetValue(BloomEffect.BaseIntensityProperty));
            }
            set
            {
                this.SetValue(BloomEffect.BaseIntensityProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne le BaseSaturation
        /// </summary>
        public double BaseSaturation
        {
            get
            {
                return ((double)this.GetValue(BloomEffect.BaseSaturationProperty));
            }
            set
            {
                this.SetValue(BloomEffect.BaseSaturationProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne le BloomIntensity
        /// </summary>
        public double BloomIntensity
        {
            get
            {
                return ((double)this.GetValue(BloomEffect.BloomIntensityProperty));
            }
            set
            {
                this.SetValue(BloomEffect.BloomIntensityProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne le BloomSaturation
        /// </summary>
        public double BloomSaturation
        {
            get
            {
                return ((double)this.GetValue(BloomEffect.BloomSaturationProperty));
            }
            set
            {
                this.SetValue(BloomEffect.BloomSaturationProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Creates an instance of the shader from the included pixel shader.
        /// </summary>
        static BloomEffect()
        {
            BloomEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/Bloom.ps");
        }

        /// <summary>
        /// Creates an instance and updates the shader's variables to the default values.
        /// </summary>
        public BloomEffect()
        {
            this.PixelShader = BloomEffect._PixelShader;

            this.UpdateShaderValue(BloomEffect.InputProperty);
            this.UpdateShaderValue(BloomEffect.BloomIntensityProperty);
            this.UpdateShaderValue(BloomEffect.BaseIntensityProperty);
            this.UpdateShaderValue(BloomEffect.BloomSaturationProperty);
            this.UpdateShaderValue(BloomEffect.BaseSaturationProperty);
        }

        #endregion
    }
}
